package com.ruoyi.controller;


import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.constants.Constant;
import com.ruoyi.dto.*;
import com.ruoyi.edu.domain.Risk;
import com.ruoyi.edu.service.IRiskService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.aspectj.weaver.loadtime.Aj;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Api(tags = "风险评估")
@RequestMapping("/riskEvaluate")
@RestController
public class RiskEvaluateController {

    @Autowired
    private IRiskService riskService;

    @ApiOperation("桥梁健康评估模型")
    @PostMapping("/bridgeHealthAssessmentModel")
    public AjaxResult BridgeHealthAssessmentModel(@RequestBody BridgeHealthDto bridgeHealthDto) {
        AjaxResult ajaxResult = new AjaxResult();


        Map map = new HashMap();
        map.put("input",bridgeHealthDto);

        Map map1 = new HashMap();
        map.put("number",bridgeHealthDto.getNumber());

        String result = Constant.BTIDGE_HEALTH_LEVEL_1;
        Integer alarm10 = 0;
        Integer alarm11 = 0;
        Integer alarm12 = 0;
        Integer alarm13 = 0;

        Integer alarm20 = 0;
        Integer alarm21 = 0;
        Integer alarm22 = 0;
        Integer alarm23 = 0;

        //塔顶偏移、锚碇位移、拱脚位移
        Integer alarm3 = 0;

        //梁端纵向位移监测  1
        if(bridgeHealthDto.isLongDispAtBeamdnd() && bridgeHealthDto.isAlarmLongDispAtBeamdnd())
        {
            if(null != bridgeHealthDto.getLongDispAtBeamdndAlarmLevel())
            {
                if(bridgeHealthDto.getLongDispAtBeamdndAlarmLevel() == 2)
                {
                    alarm12 = alarm12 +1;
                }
                else if(bridgeHealthDto.getLongDispAtBeamdndAlarmLevel() == 3)
                {
                    alarm13 = alarm13 +1;
                }
            }
        }

        //有无支座反力监测  2
        if(bridgeHealthDto.isSupportReaction() && bridgeHealthDto.isAlarmSupportReaction())
        {
            if(null != bridgeHealthDto.getSupportReactionAlarmLevel())
            {
                if(bridgeHealthDto.getSupportReactionAlarmLevel() == 2)
                {
                    alarm12 = alarm12 +1;
                }
                else if(bridgeHealthDto.getSupportReactionAlarmLevel() == 3)
                {
                    alarm13 = alarm13 +1;
                }
            }
        }

        //有无裂缝监测  3
        if(bridgeHealthDto.isCrackDetection() && bridgeHealthDto.isAlarmCrackDetection())
        {
            if(null != bridgeHealthDto.getSupportReactionAlarmLevel())
            {
                if(bridgeHealthDto.getCrackDetectionAlarmLevel() == 1)
                {
                    alarm11 = alarm11 +1;
                }
                else if(bridgeHealthDto.getCrackDetectionAlarmLevel() == 2)
                {
                    alarm12 = alarm12 +1;
                }
            }
        }

        //有无螺栓状态监测  4
        if(bridgeHealthDto.isBoltStatus() && bridgeHealthDto.isAlarmBoltStatus())
        {
            if(null != bridgeHealthDto.getBoltStatusAlarmNum())
            {
                if(bridgeHealthDto.getBoltStatusAlarmNum() > 10)
                {
                    alarm13 = alarm13 +1;
                }
                else if(bridgeHealthDto.getBoltStatusAlarmNum() >= 3)
                {
                    alarm12 = alarm12 +1;
                }
                else if(bridgeHealthDto.getBoltStatusAlarmNum() > 0)
                {
                    alarm11 = alarm11 +1;
                }
            }
        }


        //有无截面应力监测  5
        if(bridgeHealthDto.isCrossSectionalStress() && bridgeHealthDto.isAlarmCrossSectionalStress())
        {
            if(null != bridgeHealthDto.getCrossSectionalStressAlarmLevel())
            {
                if(bridgeHealthDto.getCrossSectionalStressAlarmLevel() == 1)
                {
                    alarm11 = alarm11 +1;
                }
                else if(bridgeHealthDto.getCrossSectionalStressAlarmLevel() == 2)
                {
                    alarm12 = alarm12 +1;
                }
            }
        }

        //有无索力监测  6
        if(bridgeHealthDto.isCableForce() && bridgeHealthDto.isAlarmCableForce())
        {
            if(null != bridgeHealthDto.getCableForceAlarmLevel())
            {
                if(bridgeHealthDto.getCableForceAlarmLevel() == 2)
                {
                    alarm12 = alarm12 +1;
                }
                else if(bridgeHealthDto.getCableForceAlarmLevel() == 3)
                {
                    alarm13 = alarm13 +1;
                }
            }
        }

        //有无索振动监测  7
        if(bridgeHealthDto.isCableVibration() && bridgeHealthDto.isAlarmCableVibration())
        {
            if(null != bridgeHealthDto.getCableVibrationAlarmLevel())
            {
                if(bridgeHealthDto.getCableVibrationAlarmLevel() == 1)
                {
                    alarm11 = alarm11 +1;
                }
                else if(bridgeHealthDto.getCableVibrationAlarmLevel() == 2)
                {
                    alarm12 = alarm12 +1;
                }
            }
        }

        //有无断丝监测  8
        if(bridgeHealthDto.isWireBreakage() && bridgeHealthDto.isAlarmWireBreakage())
        {
            if(null != bridgeHealthDto.getWireBreakageAlarmNum())
            {
                if(bridgeHealthDto.getWireBreakageAlarmNum() >= 3)
                {
                    alarm13 = alarm13 +1;
                }
                else if(bridgeHealthDto.getWireBreakageAlarmNum() > 0)
                {
                    alarm12 = alarm12 +1;
                }
            }
        }

        //有无索夹滑移监测  9
        if(bridgeHealthDto.isCableClampSlip() && bridgeHealthDto.isAlarmCableClampSlip())
        {
            if(null != bridgeHealthDto.getCableClampSlipAlarmNum())
            {
                if(bridgeHealthDto.getCableClampSlipAlarmNum() >= 3)
                {
                    alarm13 = alarm13 +1;
                }
                else if(bridgeHealthDto.getCableClampSlipAlarmNum() > 0)
                {
                    alarm12 = alarm12 +1;
                }
            }
        }

        //有无主梁竖向位移监测  10
        if(bridgeHealthDto.isMainBeamVerticalDisp() && bridgeHealthDto.isAlarmMainBeamVerticalDisp())
        {
            if(null != bridgeHealthDto.getMainBeamVerticalDispAlarmLevel())
            {
                if(bridgeHealthDto.getMainBeamVerticalDispAlarmLevel() == 3)
                {
                    alarm23 = alarm23 +1;
                }
                else if(bridgeHealthDto.getMainBeamVerticalDispAlarmLevel() == 2)
                {
                    alarm22 = alarm22 +1;
                }
            }
        }

        //有无主梁横向位移监测  11
        if(bridgeHealthDto.isMainBeamLateralDisp() && bridgeHealthDto.isAlarmMainBeamLateralDisp())
        {
            if(null != bridgeHealthDto.getMainBeamLateralDispAlarmLevel())
            {
                if(bridgeHealthDto.getMainBeamLateralDispAlarmLevel() == 3)
                {
                    alarm23 = alarm23 +1;
                }
                else if(bridgeHealthDto.getMainBeamLateralDispAlarmLevel() == 2)
                {
                    alarm22 = alarm22 +1;
                }
            }
        }

        //有无塔顶位移/倾斜监测  12
        if(bridgeHealthDto.isTowerTopDispTilt() && bridgeHealthDto.isAlarmTowerTopDispTilt())
        {
            if(null != bridgeHealthDto.getTowerTopDispTiltAlarmLevel())
            {
                if(bridgeHealthDto.getTowerTopDispTiltAlarmLevel() == 3)
                {
                    alarm23 = alarm23 +1;
                }
                else if(bridgeHealthDto.getTowerTopDispTiltAlarmLevel() == 2)
                {
                    alarm22 = alarm22 +1;
                    alarm3 = alarm3 + 1;
                }
            }
        }

        //有无支座位移监测  13
        if(bridgeHealthDto.isSupportDisp() && bridgeHealthDto.isAlarmSupportDisp())
        {
            if(null != bridgeHealthDto.getSupportDispAlarmLevel())
            {
                if(bridgeHealthDto.getSupportDispAlarmLevel() == 3)
                {
                    alarm23 = alarm23 +1;
                }
                else if(bridgeHealthDto.getSupportDispAlarmLevel() == 2)
                {
                    alarm22 = alarm22 +1;
                }
            }
        }

        //有无主缆偏位监测  14
        if(bridgeHealthDto.isMainCableDeflection() && bridgeHealthDto.isAlarmMainCableDeflection())
        {
            if(null != bridgeHealthDto.getMainCableDeflectionAlarmLevel())
            {
                if(bridgeHealthDto.getMainCableDeflectionAlarmLevel() == 3)
                {
                    alarm23 = alarm23 +1;
                }
                else if(bridgeHealthDto.getMainCableDeflectionAlarmLevel() == 2)
                {
                    alarm22 = alarm22 +1;
                }
            }
        }

        //有无锚碇位移监测  15
        if(bridgeHealthDto.isAnchorDisp() && bridgeHealthDto.isAlarmAnchorDisp())
        {
            if(null != bridgeHealthDto.getAnchorDispAlarmLevel())
            {
                if(bridgeHealthDto.getAnchorDispAlarmLevel() == 3)
                {
                    alarm23 = alarm23 +1;
                }
                else if(bridgeHealthDto.getAnchorDispAlarmLevel() == 2)
                {
                    alarm22 = alarm22 +1;
                    alarm3 = alarm3 + 1;
                }
            }
        }

        //有无拱脚位移监测  16
        if(bridgeHealthDto.isArchFootDisp() && bridgeHealthDto.isAlarmArchFootDisp())
        {
            if(null != bridgeHealthDto.getArchFootDispAlarmLevel())
            {
                if(bridgeHealthDto.getArchFootDispAlarmLevel() == 3)
                {
                    alarm23 = alarm23 +1;
                }
                else if(bridgeHealthDto.getArchFootDispAlarmLevel() == 2)
                {
                    alarm22 = alarm22 +1;
                    alarm3 = alarm3 + 1;
                }
            }
        }

        //有无基础冲刷深度监测  17
        if(bridgeHealthDto.isBasicScourDepth() && bridgeHealthDto.isAlarmBasicScourDepth())
        {
            if(null != bridgeHealthDto.getBasicScourDepthAlarmLevel())
            {
                if(bridgeHealthDto.getBasicScourDepthAlarmLevel() == 3)
                {
                    alarm23 = alarm23 +1;
                }
                else if(bridgeHealthDto.getBasicScourDepthAlarmLevel() == 2)
                {
                    alarm22 = alarm22 +1;
                }
            }
        }

        //有无高墩墩顶位移监测  18
        if(bridgeHealthDto.isHighPierTopDisp() && bridgeHealthDto.isAlarmHighPierTopDisp())
        {
            if(null != bridgeHealthDto.getHighPierTopDispAlarmLevel())
            {
                if(bridgeHealthDto.getHighPierTopDispAlarmLevel() == 3)
                {
                    alarm23 = alarm23 +1;
                }
                else if(bridgeHealthDto.getHighPierTopDispAlarmLevel() == 2)
                {
                    alarm22 = alarm22 +1;
                }
            }
        }

        //有无桥身预应力监测  19
        if(bridgeHealthDto.isBridgePrestressing() && bridgeHealthDto.isAlarmBridgePrestressing())
        {
            if(null != bridgeHealthDto.getBridgePrestressingAlarmLevel())
            {
                if(bridgeHealthDto.getBridgePrestressingAlarmLevel() == 3)
                {
                    alarm23 = alarm23 +1;
                }
                else if(bridgeHealthDto.getBridgePrestressingAlarmLevel() == 2)
                {
                    alarm22 = alarm22 +1;
                }
            }
        }

        //有无主梁振动监测  20
        if(bridgeHealthDto.isMainBeamVibration() && bridgeHealthDto.isAlarmMainBeamVibration())
        {
            if(null != bridgeHealthDto.getMainBeamVibrationAlarmLevel())
            {
                if(bridgeHealthDto.getMainBeamVibrationAlarmLevel() == 3)
                {
                    alarm23 = alarm23 +1;
                }
                else if(bridgeHealthDto.getMainBeamVibrationAlarmLevel() == 2)
                {
                    alarm22 = alarm22 +1;
                }
                else if(bridgeHealthDto.getMainBeamVibrationAlarmLevel() == 1)
                {
                    alarm21 = alarm21 +1;
                }
            }
        }

        if(alarm13 >0 || alarm23 >1)
        {
            result = Constant.HIDDEN_TROUBLE_LEVEL_4;
        }
        else if(alarm12 >0 || alarm23 == 1 || alarm22 > 1 || alarm3 > 0)
        {
            result = Constant.HIDDEN_TROUBLE_LEVEL_3;
        }
        else if(alarm11 >0 || alarm22 == 1)
        {
            result = Constant.HIDDEN_TROUBLE_LEVEL_2;
        }
        else
        {
            result = Constant.HIDDEN_TROUBLE_LEVEL_1;
        }

        System.out.println(alarm10);
        System.out.println(alarm11);
        System.out.println(alarm12);
        System.out.println(alarm13);
        System.out.println(alarm20);
        System.out.println(alarm21);
        System.out.println(alarm22);
        System.out.println(alarm23);
        System.out.println(alarm3);

        map.put("alarm10",alarm10);
        map.put("alarm11",alarm11);
        map.put("alarm12",alarm12);
        map.put("alarm13",alarm13);
        map.put("alarm20",alarm20);
        map.put("alarm21",alarm21);
        map.put("alarm22",alarm22);
        map.put("alarm23",alarm23);

        map.put("assessmentResult",result);

        return ajaxResult.success(map);
    }


    public static void main(String[] args) {
        /*JtDto jtDto = new JtDto();
        jtDto.setBjcz("1");
        jtDto.setCllx("2");
        jtDto.setQxzk("2");
        jtDto.setYshx("1");
        jtDto.setWhps("1");
        jtDto.setSzlw("1");
        jtDto.setClsz("1");
        jtDto.setSfaz("1");
        jtDto.setJksf("1");
        jtDto.setYshx("1");
        jtDto.setYshx("1");
        RiskEvaluateController risk = new RiskEvaluateController();
        Double score = risk.calculateScore(jtDto,jtDictMap,"DT");*/
        Integer score = 0;
        score += 1;
        System.out.println(score);
    }
}
